package com.gitee.kamismile.akkaEx.actor;

import akka.actor.ActorRef;
import akka.cluster.pubsub.DistributedPubSub;
import com.gitee.kamismile.akka.core.BaseActor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import scala.PartialFunction;
import scala.runtime.BoxedUnit;

//@Component
//@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class A extends BaseActor {

    //    private ActorRef actorRef;
    ApplicationContext applicationContext;
    public A(Object... obj) {
        this.applicationContext= (ApplicationContext) obj[0];
//        actorRef = DistributedPubSub.get(getContext().system()).mediator();
    }




    @Override
    public Receive createReceive() {
        return receiveBuilder()
                .match(String.class, s-> {
                    ActorRef bActorRef = applicationContext.getBean("bActorRef",ActorRef.class);
                    bActorRef.tell(s,self());
                    System.out.println("gogogoogo11111111111g"+s);
                        }
                )
                .matchAny(s->unhandled(s))
                .build();
    }

//    @Override
//    public void onReceive(Object message) throws Throwable, Throwable {
//        System.out.println(applicationContext);
//        System.out.println("gogogoogog"+message);
//    }
}
